package high.concurrent.pay.factory;

import high.concurrent.pay.service.impl.AddAccountAmountImpl;
import high.concurrent.pay.strategypattern.callback.PayCallbackContext;
import high.concurrent.vo.PayInfoVO;

import java.util.ArrayList;
import java.util.List;

/**
 * 支付回调工厂模式
 */
public class PayCallbackFactory {

    /**
     * 向各相关服务发送消息， 消息标识待发送
     * @param payInfoVO
     * @return
     */
    public List<String> toBeSend(PayInfoVO payInfoVO){

        List<String> messageIds = new ArrayList<>();
        PayCallbackContext payCallbackContext = new PayCallbackContext(new AddAccountAmountImpl());
        messageIds = payCallbackContext.toBeSend(payInfoVO);
        return messageIds;
    }

    /**
     * 修改订单状态为已完成
     * @param payInfoVO
     */
    public void updateLocalTransaction(PayInfoVO payInfoVO) {

        PayCallbackContext payCallbackContext = new PayCallbackContext(new AddAccountAmountImpl());
        payCallbackContext.updateLocalTransaction(payInfoVO);
    }

    /**
     * 向各服务发送消息， 消息标识为已发送
     * @param messageIds
     */
    public void hasBeenSent(List<String> messageIds) {

        // 向各服务发送   已发送类型的消息，所有类型支付都一样，都是给啥id传啥id，所以用NetCostImpl即可，这里再优化下
        PayCallbackContext payCallbackContext = new PayCallbackContext(new AddAccountAmountImpl());
        payCallbackContext.hasBeenSent(messageIds);
    }

}
